import { modal } from 'vue-strap'
import { showMsg, fakeAdd } from '../../../../vuex/action'

export default {
  name: 'fake-record-config',
  props: ['showFakeAdd', 'activityId'],
  data() {
    return {
      title: '增加假记录',
      fakeRecord: {
        activityId: +this.activityId,
        phone: '',
        name: '',
        rate: null
      }
    }
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xFakeAdd: fakeAdd
    }
  },
  components: {
    'vue-modal': modal
  },
  methods: {
    submit() {
      if (this.fakeRecord.phone.length !== 11) {
        return this.xShowMsg({
          type: 'danger',
          content: '请输入正确的手机号码'
        })
      }
      this.fakeRecord.rate = +this.fakeRecord.rate
      this.xFakeAdd(this.fakeRecord)
        .then(() => {
          this.showFakeAdd = false
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    addFakeRecord() {
      this.fakeRecord = {
        activityId: +this.activityId,
        phone: '',
        name: '',
        rate: null
      }
      this.showFakeAdd = true
    }
  }
}
